package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.UmsRoleMenuRelationMapper;
import com.mall.pojo.UmsRoleMenuRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsRoleMenuRelationApiImpl implements UmsRoleMenuRelationApi{

    @Autowired
    private UmsRoleMenuRelationMapper roleMenuRelationMapper;

    /**
     * 根据角色id查询菜单关联信息
     * @param roleId
     * @return
     */
    @Override
    public List<UmsRoleMenuRelation> findByRole(Long roleId) {
        LambdaQueryWrapper<UmsRoleMenuRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleMenuRelation::getRoleId,roleId);
        return roleMenuRelationMapper.selectList(wrapper);
    }

    @Override
    public void add(UmsRoleMenuRelation relation) {
        roleMenuRelationMapper.insert(relation);
    }

    @Override
    public void delete(Integer roleId) {
        LambdaQueryWrapper<UmsRoleMenuRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleMenuRelation::getRoleId,roleId);
        roleMenuRelationMapper.delete(wrapper);
    }
}
